Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default auditing options. #60739

Merged
merged 1 commit into from
Mar 13, 2018

Conversation

tallclair
Copy link
Member

  • Log backend defaults to blocking mode (backwards compatability)
  • Webhook backend defaults to throttled
  • Fix webhook validation
  • Add options test

Which issue(s) this PR fixes:
Fixes #60719

Special notes for your reviewer:
This PR is an alternative fix to #60727. If the rollback goes in first, I'll rebase this on a roll-forward.

Release note:
-->

NONE

@tallclair tallclair added kind/bug Categorizes issue or PR as related to a bug. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. sig/auth Categorizes an issue or PR as relevant to SIG Auth. labels Mar 2, 2018
@tallclair tallclair added this to the v1.10 milestone Mar 2, 2018
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 2, 2018
@k8s-ci-robot k8s-ci-robot requested review from dims and ncdc March 2, 2018 23:25
// Don't validate the unused options.
return nil
}
config := options.BatchConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if --audit-log-batch-max-wait is set to zero?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will hotloop. Not great, but not exactly invalid. I'd prefer to leave it as-is here.

@thockin
Copy link
Member

thockin commented Mar 5, 2018

This change is Reviewable

Copy link

@crassirostris crassirostris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM

Log backend defaults to blocking mode (backwards compatability)

This is still a rollback. I think batching behavior is better by default

@@ -101,3 +101,7 @@ func (b *backend) processEvents(ev ...*auditinternal.Event) error {
return b.w.RestClient.Post().Body(&list).Do()
}).Error()
}

func (b *backend) String() string {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not Name()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way just supports calling fmt.Sprintf("%s", ...), and resolves to something if String isn't set. I opted not to add it to the backend interface. But I don't have a strong preference, it's sort of a hack to get the test working.

@CaoShuFeng
Copy link
Contributor

I think batching behavior is better by default

I am OK with it, if the new behavior is well documented.

@tallclair
Copy link
Member Author

Re: default to batch - I think we should merge this (revert defaults), and then follow up with a separate PR to change just the log default (maybe wait for 1.11). I could add a release note or help text stating that the default will change in the future.

func (u union) String() string {
var backendStrings []string
for _, backend := range u.backends {
backendStrings = append(backendStrings, fmt.Sprintf("%s", backend))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why not backend.String() instead of printf("%s", ...) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backend interface doesn't have string. I could add String() (or just Name()) to the interface, or try to cast to fmt.Stringer here, but I thought the Sprintf was simpler. I don't have any real preference though...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's fine as it is then.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually prefer to have a dedicated method in the interface. Otherwise you have to have implicit knowledge that stringifying a backend should give a short name of the backend, not e.g. full struct

if err := validateBackendBatchConfig(pluginwebhook.PluginName, o.LogOptions.BatchOptions.BatchConfig); err != nil {
allErrors = append(allErrors, err)
if o.WebhookOptions.enabled() {
if err := validateBackendBatchOptions(pluginwebhook.PluginName, o.WebhookOptions.BatchOptions); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pattern we have everywhere else is to pass o.WebhookOptions to the validate func and check for nil (and ConfigFile) locally. This style complicates the code by making complexity non-local.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if o.LogOptions.MaxSize < 0 {
allErrors = append(allErrors, fmt.Errorf("--audit-log-maxsize %v can't be a negative number", o.LogOptions.MaxSize))
// Check validities of MaxAge, MaxBackups and MaxSize of log options, if file log backend is enabled.
if o.LogOptions.enabled() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the whole block belongs into validateLogOptions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@crassirostris
Copy link

As I've mentioned in #60719 (comment)

I think this PR should be merged before the freeze, the default parameters for the log backend should change.

I don't think it's possible currently to limit the number of goroutines running at the same time in the batching backend, so our option would be either to set the low flush timeout or low max batch size. The former is better, since the chance to have events ordered is higher and it allows to avoid write contention.

@liggitt
Copy link
Member

liggitt commented Mar 6, 2018

/unassign
will let @tallclair weigh in on whether this is required for 1.10 now

@tallclair
Copy link
Member Author

Discussed with @crassirostris, I think we should try and get this into 1.10. I'll address the comments in the next hour.

@k8s-github-robot
Copy link

[MILESTONENOTIFIER] Milestone Pull Request: Up-to-date for process

@crassirostris @sttts @tallclair

Pull Request Labels
  • sig/auth: Pull Request will be escalated to these SIGs if needed.
  • priority/critical-urgent: Never automatically move pull request out of a release milestone; continually escalate to contributor and SIG through all available channels.
  • kind/bug: Fixes a bug discovered during the current release.
Help

@tallclair
Copy link
Member Author

Addressed feedback. I think the only unresolved issue is whether I should just add a "Name()" method to the backend interface.

@ericchiang
Copy link
Contributor

Errors from golint:
staging/src/k8s.io/apiserver/plugin/pkg/audit/buffered/buffered.go:31:1: comment on exported const PluginName should be of the form "PluginName ..."

Please review the above warnings. You can test via "golint" and commit the result.
If the above warnings do not make sense, you can exempt this package from golint
checking by adding it to hack/.golint_failures (if your reviewer is okay with it).

@@ -116,15 +116,15 @@ func NewAuditOptions() *AuditOptions {
WebhookOptions: AuditWebhookOptions{
BatchOptions: AuditBatchOptions{
Mode: ModeBatch,
BatchConfig: defaultLogBatchConfig,
BatchConfig: pluginbuffered.NewDefaultBatchConfig(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crassirostris please confirm that these settings are what we want.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, though it's preferrable to merge this PR after #60926, to avoid showing regressions in the scale tests

@sttts
Copy link
Contributor

sttts commented Mar 8, 2018

Looks good structurally. Please squash. @crassirostris ptal at the default config: #60739 (comment)

- Log backend defaults to blocking mode (backwards compatability)
- Fix webhook validation
- Add options test
@sttts
Copy link
Contributor

sttts commented Mar 9, 2018

/approve

Leaving final lgtm to @crassirostris

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 9, 2018
@crassirostris
Copy link

@tallclair Please unhold when #60926 is merged to avoid breaking scale tests

/lgtm
/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Mar 9, 2018
k8s-github-robot pushed a commit that referenced this pull request Mar 10, 2018
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Make log audit backend configurable in GCE

This PR will allow to enable audit logging batching by default in e2e tests, after #60739 is merged. This is an important step to prevent a regression in scale tests.

/cc @tallclair @sttts 

/assign @roberthbailey 

Robert, please approve

```release-note
NONE
```
@jdumars
Copy link
Member

jdumars commented Mar 13, 2018

@tallclair PTAL at test output

@crassirostris
Copy link

Unable to load build details

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: crassirostris, sttts, tallclair

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ericchiang
Copy link
Contributor

#60926 is merged. @crassirostris can you remove your hold?

@crassirostris crassirostris removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 13, 2018
@crassirostris
Copy link

@ericchiang Thanks for pointing this out, done

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 60737, 60739, 61080, 60968, 60951). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit c13d9ff into kubernetes:master Mar 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/audit cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/critical-urgent Highest priority. Must be actively worked on as someone's top priority right now. release-note-none Denotes a PR that doesn't merit a release note. sig/auth Categorizes an issue or PR as relevant to SIG Auth. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Advanced Audit tests flaking
10 participants